
var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		erpReport: {},
        ureportList: [],
		q: {
			reportName:null
		},

	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.erpReport = {};
		},
		reset:function(){
			vm.q.reportName= '';
		},
		update: function (event) {
			var reId = getSelectedRow();
			if(reId == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(reId)
		},
		saveOrUpdate: function (event) {
            if(vm.validator()){
                return ;
            }
			var url = vm.erpReport.reId == null ? "report/erpreport/save" : "report/erpreport/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.erpReport),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
            ;
            var reId = getSelectedRow();
            if(reId == null){
                return ;
            }
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "report/erpreport/delete",
                    contentType: "application/json",
				    data: JSON.stringify(reId),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(reId){
			$.get(baseURL + "report/erpreport/info/"+reId, function(r){
                vm.erpReport = r.erpReport;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page,
				postData:{
					'reportName': vm.q.reportName
				},
            }).trigger("reloadGrid");
		},
        validator: function () {
            if(isBlank(vm.erpReport.reportName)){
                alert("报表名称不能为空");
                return true;
            }
			if(isBlank(vm.erpReport.reportCategory)){
				alert("报表分类不能为空");
				return true;
			}
        },
	}
});


$(function () {
	$("#jqGrid").jqGrid({
		url: baseURL + 'report/erpreport/list',
		datatype: "json",
		colModel: [
			{ label: 'ID', name: 'reId', index: 're_id', width: 50, key: true },
			{ label: '报表名称', name: 'reportName', index: 'report_name', width: 80 },
			{ label: '报表分类', name: 'reportCategory', index: 'report_category', width: 80 },
			{ label: '备注', name: 'reportRemark', index: 'report_remark', width: 80 },
			{ label: '报表路径', name: 'reportPath', index: 'report_path', width: 100 },
			{ label: '创建人', name: 'createName', index: 'create_name', width: 80 },
			{ label: '创建时间', name: 'createTime', index: 'create_time', width: 80 }
		],
		viewrecords: true,
		height: 385,
		rowNum: 10,
		rowList : [10,30,50],
		rownumbers: true,
		rownumWidth: 25,
		autowidth:true,
		multiselect: true,
		pager: "#jqGridPager",
		jsonReader : {
			root: "page.list",
			page: "page.currPage",
			total: "page.totalPage",
			records: "page.totalCount"
		},
		prmNames : {
			page:"page",
			rows:"limit",
			order: "order"
		},
		gridComplete:function(){
			//隐藏grid底部滚动条
			$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
		}
	});
	$.ajax({
		type: "POST",
		url: baseURL + "report/erpreport/ureportMaplist",
		contentType: "application/json",
		data: null,
		success: function(r){
			console.log(r.ureportList);
			vm.ureportList = r.ureportList;
		}
	});
});